package xuecheng.tool.mq.rabbitmq.delay;

import java.util.Map;

import org.springframework.amqp.core.CustomExchange;

import com.google.common.collect.Maps;

import lombok.Data;
import xuecheng.tool.mq.rabbitmq.ExchangeType;

/**
 * 延时消息交换机
 *
 * 大前提: 安装了 rabbitmq_delayed_message_exchange 插件
 *
 * @author PengXueCheng
 * @version 1.0.0
 **/
public class DelayedExchange extends CustomExchange {

    /**
     *
     * @param name
     *            交换机名称
     * @param exchangeType
     *            交换机类型
     */
    public DelayedExchange(String name, ExchangeType exchangeType) {
        super(name, "x-delayed-message", true, false, new ArgsObj(exchangeType).getValue());
    }

    @Data
    private static class ArgsObj {

        private Map<String, Object> value;

        ArgsObj(ExchangeType type) {
            this.value = getValue(type);
        }

        private Map<String, Object> getValue(ExchangeType exchangeType) {
            Map<String, Object> args = Maps.newHashMap();
            args.put("x-delayed-type", exchangeType.getValue());
            return args;
        }

    }

}
